
public class Vektor {
	private double angle, magnitude, cathetusX, cathetusY;

	public Vektor(double cathetusX, double cathetusY) {
		this.cathetusX = cathetusX;
		this.cathetusY = cathetusY;
		this.angle = calculateAngle(cathetusX, cathetusY);
		this.magnitude = calculateMagnitude(cathetusX, cathetusY);
	}

	public double getCathetusX() {
		return cathetusX;
	}

	public void setCathetusX(double cathetusX) {
		this.cathetusX = cathetusX;
		angle = calculateAngle(cathetusX, cathetusY);
		magnitude = calculateMagnitude(cathetusX, cathetusY);
	}

	public double getCathetusY() {
		return cathetusY;
	}

	public void setCathetusY(double cathetusY) {
		this.cathetusY = cathetusY;
		angle = calculateAngle(cathetusX, cathetusY);
		magnitude = calculateMagnitude(cathetusX, cathetusY);
	}
	
	public double getAngle() {
		return angle;
	}
	public void setAngle(double angle) {
		this.angle = angle;
		cathetusX = calculateCathetusX(angle);
		cathetusY = calculateCathetusY(angle);
	}

	public double getMagnitude() {
		return magnitude;
	}
	
	public void rotate(double systemRotation) {
		double newAngle = angle-systemRotation;
		setAngle(newAngle);
	}
	@Override
	public boolean equals(Object obj) {
		Vektor v = (Vektor)obj;
		if(v.getAngle() == angle && v.getCathetusX() == cathetusX && v.getCathetusY() == cathetusY)
			return true;
		else
			return false;
	}
	
	public Vektor clone() {
		return new Vektor(cathetusX, cathetusY);
	}
	
	/**
	 * Private methods
	 */
	private double calculateMagnitude(double catX, double catY) {
		return Math.sqrt((catX*catX)+(catY*catY));
	}
	private double calculateAngle(double catX, double catY) {
		return Math.atan2(catY, catX);
	}
	private double calculateCathetusX(double angle) {
		return magnitude*Math.cos(angle);
	}
	private double calculateCathetusY(double angle) {
		return magnitude*Math.sin(angle);
	}
}
